package client;
// This file contains material supporting section 3.7 of the textbook:
// "Object Oriented Software Engineering" and is issued under the open-source
// license found at www.lloseng.com 

import java.io.*;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Time;
import java.util.Date;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

import com.sun.rowset.CachedRowSetImpl;

import Controller.DBcontroller;
import Entity.*;
import Entity.Packet.Kind;
import Entity.Worker.Role;
import GUI.FrameIS;
import GUI.FrameSystem;
import common.*;

/**
 * This class constructs the UI for a chat client.  It implements the
 * chat interface in order to activate the display() method.
 * Warning: Some of the code here is cloned in ServerConsole 
 *
 * @author Fran&ccedil;ois B&eacute;langer
 * @author Dr Timothy C. Lethbridge  
 * @author Dr Robert Lagani&egrave;re
 * @version July 2000
 */
public class ClientConsole implements ChatIF 
{
	private static Packet input;
  //Class variables *************************************************
  
  /**
   * The default port to connect on.
   */
  final public static int DEFAULT_PORT = 5555;
  
  //Instance variables **********************************************
  
  /**
   * The instance of the client that created this ConsoleChat.
   */
  static ChatClient client;

  
  //Constructors ****************************************************

  /**
   * Constructs an instance of the ClientConsole UI.
   *
   * @param host The host to connect to.
   * @param port The port to connect on.
   */
  public ClientConsole(String host, int port) 
  {
    try 
    {
      client= new ChatClient(host, port, this);
    } 
    catch(IOException exception) 
    {
      System.out.println("Error: Can't setup connection!"
                + " Terminating client.");
      System.exit(1);
    }
  }

  
  //Instance methods ************************************************
  
  /**
   * This method waits for input from the console.  Once it is 
   * received, it sends it to the client's message handler.
   */
  public void accept() 
  {
    try
    {
      BufferedReader fromConsole = 
        new BufferedReader(new InputStreamReader(System.in));
      String message;

      while (true) 
      {
        message = fromConsole.readLine();
        client.handleMessageFromClientUI(message);
    	  
      }
    } 
    catch (Exception ex) 
    {
      System.out.println
        ("Unexpected error while reading from console!");
    }
  }
  
  public Customer[] getCustomers()
  {
	  int count=0;
	  this.input=null;
	  Packet p=new Packet();
	  p.setE(Kind.get);
	  String query="SELECT * FROM test.Customer;";
	  p.setO(query);
	  try {
		 
			client.sendToServer((Object)p);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		  while (input==null);
		  CachedRowSetImpl rs=(CachedRowSetImpl)input.getO();
		  
		  try {
			while(rs.next())
			  {
				  count++;
			  }
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		  try {
			rs.beforeFirst();
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		  Customer[] cus=new Customer[count];
		  int i=0;
		  try {
			while(rs.next())
			  {
			try {
				cus[i]=new Customer(rs.getString(1),rs.getString(2),rs.getString(3),rs.getString(4),rs.getString(5));
				cus[i].setAcc_balance(rs.getDouble(6));
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
				i++;	
				 // Print out the values
				// System.out.println(rs.getString(1)+"  " +rs.getString(2));
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		  return cus;
  }
  
  public FullSubscription [] getFullSubscriptions()
  {
	  int count=0;
	  this.input=null;
	  Packet p=new Packet();
	  p.setE(Kind.get);
	  String query="SELECT * FROM test.FullSubscription;";
	  p.setO(query);
	  try {
		 
			client.sendToServer((Object)p);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		  while (input==null);
		  CachedRowSetImpl rs=(CachedRowSetImpl)input.getO();
		  
		  try {
			while(rs.next())
			  {
				  count++;
			  }
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		  try {
			rs.beforeFirst();
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		  FullSubscription [] subs=new FullSubscription [count];
		  int i=0;
		  try {
			while(rs.next())
			  {
			try {
				subs[i]=new FullSubscription();
				subs[i].setSubscription_number(rs.getString(1));
				subs[i].setCustomer_id(rs.getString(2));
				subs[i].setCar_number(rs.getString(3));
				Date sd=new Date(rs.getLong(4));
				subs[i].setStart_date(sd);
				Date ed=new Date(rs.getLong(5));
				subs[i].setEnd_date(ed);
				subs[i].setPenalty(rs.getInt(6));
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
				i++;	
				 // Print out the values
				// System.out.println(rs.getString(1)+"  " +rs.getString(2));
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		  return subs;
  }
  
	public CasualSubscription [] getCasualSubscriptions()
	{
		  int count=0;
		  this.input=null;
		  Packet p=new Packet();
		  p.setE(Kind.get);
		  String query="SELECT * FROM test.CasualSubscription;";
		  p.setO(query);
		  try {
			 
				client.sendToServer((Object)p);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			  while (input==null);
			  CachedRowSetImpl rs=(CachedRowSetImpl)input.getO();
			  
			  try {
				while(rs.next())
				  {
					  count++;
				  }
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			  try {
				rs.beforeFirst();
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			  CasualSubscription [] Csubs=new  CasualSubscription [count];
			  int i=0;
			  try {
				while(rs.next())
				  {
				try {
					Csubs[i]=new CasualSubscription();
					Csubs[i].setSubscription_number(rs.getString(1));
					Csubs[i].setCustomer_id(rs.getString(2));
					Csubs[i].setCar_number(rs.getString(3));
					Date sd=new Date(rs.getLong(4));
					Csubs[i].setStart_date(sd);
					Date ed=new Date(rs.getLong(5));
					Csubs[i].setEnd_date(ed);
					Csubs[i].setParking_lot_number(rs.getInt(6));
					Time lt=new Time(rs.getLong(7));
					Csubs[i].setleaving_time(lt);
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
					i++;	
					 // Print out the values
					// System.out.println(rs.getString(1)+"  " +rs.getString(2));
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} 
			  return Csubs;	
	}
  
	public int getNumOfOrders(Date start,Date end,int pl)
	{
			int count=0;
			input=null;
			Packet p=new Packet();
			p.setE(Kind.get);
			String query="SELECT * FROM test.Order WHERE Order.ParkingLotNumber="+pl+" AND Order.OrderDate>"+start.getTime()+" AND Order.OrderDate<"+end.getTime()+";";
			p.setO(query);
			try {
				client.sendToServer((Object)p);
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			while (input==null);
			CachedRowSetImpl rs=(CachedRowSetImpl)input.getO();
			try {
				while(rs.next())
				{
					count++;
				}
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			} 
			return count;
		}
	
	public int getNumOfSubsOrders(Date start,Date end,int pl)
	{
			int count,count1,count2;
			input=null;
			Packet p=new Packet();
			p.setE(Kind.get);
			try {
				client.sendToServer((Object)p);
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			count1=getNumOfCasualSubscription(start,end,pl);
			count2=getNumOfFullSubscription(start,end);
			count=count1+count2;
			return count;
		}
	public int getNumOfCasualSubscription(Date start,Date end,int pl)
	{
			int count=0;
			input=null;
			Packet p=new Packet();
			p.setE(Kind.get);
			String query="SELECT * FROM test.CasualSubscription WHERE CasualSubscription.ParkingLotNumber="+pl+" AND CasualSubscription.StartDate>="+start.getTime()+" AND CasualSubscription.EndDate<="+end.getTime()+";";
			p.setO(query);
			try {
				client.sendToServer((Object)p);
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			while (input==null);
			CachedRowSetImpl rs=(CachedRowSetImpl)input.getO();
			try {
				while(rs.next())
				{
					count++;
				}
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			} 
			return count;
		}
	
	public int getNumOfFullSubscription(Date start,Date end)
	{
			int count=0;
			input=null;
			Packet p=new Packet();
			p.setE(Kind.get);
			String query="SELECT * FROM test.FullSubscription WHERE FullSubscription.StartDate=>"+start.getTime()+" AND CasualSubscription.EndDate<="+end.getTime()+";";
			p.setO(query);
			try {
				client.sendToServer((Object)p);
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			while (input==null);
			CachedRowSetImpl rs=(CachedRowSetImpl)input.getO();
			try {
				while(rs.next())
				{
					count++;
				}
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			} 
			return count;
		}
	
	public Complaint[] getComplaints(Date start,Date end) 
	{
		int count=0;
		input=null;
		Packet p=new Packet();
		p.setE(Kind.get);
		String query="SELECT * FROM test.Comlaint WHERE Complaint.SubmissonDate>="+start.getTime()+" AND Complaint.SubmissonDate<="+end.getTime()+";";
		p.setO(query);
		try {
			client.sendToServer((Object)p);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		while (input==null);
		CachedRowSetImpl rs=(CachedRowSetImpl)input.getO();
		try {
			while(rs.next())
			{
				count++;
			}
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} 
		try {
			rs.beforeFirst();
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		Complaint [] c=new Complaint[count];
		int i=0;
		try {
			while(rs.next())
			{
				Date begin=new Date(rs.getLong(3)),ans=new Date(rs.getLong(8));
				
				c[i]=new Complaint(rs.getString(2),rs.getString(4));
				c[i].setComplaint_number(rs.getInt(1));
				c[i].setDateOfsubmission(begin);
				c[i].setHandled(rs.getBoolean(5));
				c[i].setWorker_id(rs.getString(6));
				c[i].setResult(rs.getString(7));
				c[i].setDateOfAnswer(ans);
				c[i].setCompensation(rs.getDouble(9));
				i++;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		return c;
	}
	public int getCompleteOrder(Date s,Date e,int parkingLot) 
	{
		int count=0;
		input=null;
		Packet p=new Packet();
		p.setE(Kind.get);
		String query="SELECT * FROM test.Order WHERE Order.ParkingLotNumber="+parkingLot+" AND Order.OrderDate>"+s.getTime()+" AND Order.OrderDate<"+e.getTime()+" AND Order.AcctualLeavingDate IS NOT NULL;";
		p.setO(query);
		try {
			client.sendToServer((Object)p);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		while (input==null);
		CachedRowSetImpl rs=(CachedRowSetImpl)input.getO();
		try {
			while(rs.next())
			{
				count++;
			}
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} 
		return count;
	}
	public int getUnCompleteOrder(Date s,Date e,int parkingLot) 
	{
		int count=0;
		input=null;
		Packet p=new Packet();
		p.setE(Kind.get);
		String query="SELECT * FROM test.Order WHERE Order.ParkingLotNumber="+parkingLot+" AND Order.OrderDate>"+s.getTime()+" AND Order.OrderDate<"+e.getTime()+" AND Order.AcctualLeavingDate IS NULL;";
		p.setO(query);
		try {
			client.sendToServer((Object)p);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		while (input==null);
		CachedRowSetImpl rs=(CachedRowSetImpl)input.getO();
		try {
			while(rs.next())
			{
				count++;
			}
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} 
		return count;
	}
	public Order[] getOrders() 
	{
		int count=0;
		input=null;
		Packet p=new Packet();
		p.setE(Kind.get);
		String query="SELECT * FROM test.Order;";
		p.setO(query);
		try {
			client.sendToServer((Object)p);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		while (input==null);
		CachedRowSetImpl rs=(CachedRowSetImpl)input.getO();
		try {
			while(rs.next())
			{
				count++;
			}
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} 
		try {
			rs.beforeFirst();
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		Order [] c=new Order[count];
		int i=0;
		try {
			while(rs.next())
			{
				Date orderDate=new Date(rs.getLong(4)),arrivalDate=new Date(rs.getLong(6)),leavingDate=new Date(rs.getLong(8)),acctualArr=new Date(rs.getLong(9)),acctualleav=new Date(rs.getLong(10));
				
				c[i]=new Order(rs.getString(2),rs.getString(3),rs.getInt(7),arrivalDate,leavingDate,rs.getString(11));
				c[i].setActualArrivalDate(acctualArr);
				c[i].setActualLeavingDate(acctualleav);
				c[i].setCanceled(rs.getBoolean(5));
				c[i].setOrderDate(orderDate);
				i++;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		return c;
	}
	public Order[] getLateness(int parkingLot)
	{
		int count=0;
		input=null;
		Packet p=new Packet();
		p.setE(Kind.get);
		String query="SELECT * FROM test.Order WHERE Order.ParkingLotNumber="+parkingLot+" AND Order.AcctualArrivalDate>Order.ArrivalDate;";
		p.setO(query);
		try {
			client.sendToServer((Object)p);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		while (input==null);
		CachedRowSetImpl rs=(CachedRowSetImpl)input.getO();
		try {
			while(rs.next())
			{
				count++;
			}
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} 
		try {
			rs.beforeFirst();
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		Order [] c=new Order[count];
		int i=0;
		try {
			while(rs.next())
			{
				Date orderDate=new Date(rs.getLong(4)),arrivalDate=new Date(rs.getLong(6)),leavingDate=new Date(rs.getLong(8)),acctualArr=new Date(rs.getLong(9)),acctualleav=new Date(rs.getLong(10));
				
				c[i]=new Order(rs.getString(2),rs.getString(3),rs.getInt(7),arrivalDate,leavingDate,rs.getString(11));
				c[i].setActualArrivalDate(acctualArr);
				c[i].setActualLeavingDate(acctualleav);
				c[i].setCanceled(rs.getBoolean(5));
				c[i].setOrderDate(orderDate);
				i++;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		return c;
	}
	public int getNumOfCanceled(int p)
	{
		int count=0;
		input=null;
		Packet p1=new Packet();
		p1.setE(Kind.get);
		String query="SELECT * FROM test.Order WHERE Order.ParkingLotNumber="+p+" AND Order.AcctualLeavingDate IS TRUE;";
		p1.setO(query);
		try {
			client.sendToServer((Object)p1);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		while (input==null);
		CachedRowSetImpl rs=(CachedRowSetImpl)input.getO();
		try {
			while(rs.next())
			{
				count++;
			}
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} 
		return count;
	}
	public OrderReport[] getOrderReports() 
	{
		int count=0;
		input=null;
		Packet p=new Packet();
		p.setE(Kind.get);
		String query="SELECT * FROM test.OrderReport;";
		p.setO(query);
		try {
			client.sendToServer((Object)p);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		while (input==null);
		CachedRowSetImpl rs=(CachedRowSetImpl)input.getO();
		try {
			while(rs.next())
			{
				count++;
			}
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} 
		try {
			rs.beforeFirst();
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		OrderReport [] c=new OrderReport[count];
		int i=0;
		try {
			while(rs.next())
			{
				Date begin=new Date(rs.getLong(1)),end=new Date(rs.getLong(2));
				
				c[i]=new OrderReport(begin,end,rs.getString(3),rs.getInt(4));
				c[i].setNumOfInAdvance(rs.getInt(7));
				c[i].setNumOfOrders(rs.getInt(5));
				c[i].setNumOfSubsOrders(rs.getInt(6));
				i++;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		return c;
	}
	public ComplaintReport[] getComplaintReports() 
	{
		int count=0;
		input=null;
		Packet p=new Packet();
		p.setE(Kind.get);
		String query="SELECT * FROM test.ComplaintReport;";
		p.setO(query);
		try {
			client.sendToServer((Object)p);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		while (input==null);
		CachedRowSetImpl rs=(CachedRowSetImpl)input.getO();
		try {
			while(rs.next())
			{
				count++;
			}
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} 
		try {
			rs.beforeFirst();
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		ComplaintReport [] c=new ComplaintReport[count];
		int i=0;
		try {
			while(rs.next())
			{
				Date begin=new Date(rs.getLong(1)),end=new Date(rs.getLong(2));
				
				c[i]=new ComplaintReport(begin,end,rs.getString(3),rs.getInt(4));
				i++;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		return c;
	}
	public DisabledReport[] getDisabledReports() 
	{
		int count=0;
		input=null;
		Packet p=new Packet();
		p.setE(Kind.get);
		String query="SELECT * FROM test.DisabledReport;";
		p.setO(query);
		try {
			client.sendToServer((Object)p);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		while (input==null);
		CachedRowSetImpl rs=(CachedRowSetImpl)input.getO();
		try {
			while(rs.next())
			{
				count++;
			}
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} 
		try {
			rs.beforeFirst();
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		DisabledReport [] c=new DisabledReport[count];
		int i=0;
		try {
			while(rs.next())
			{
				Date begin=new Date(rs.getLong(1)),end=new Date(rs.getLong(2));
				
				c[i]=new DisabledReport(begin,end,rs.getString(3),rs.getInt(4));
				i++;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		return c;
	}
	public int getNumOfCasualSubs(int parkinglot)
	{
		int count=0;
		input=null;
		Packet p1=new Packet();
		p1.setE(Kind.get);
		String query="SELECT * FROM test.CasualSubscription WHERE CasualSubscription.ParkingLotNumber="+parkinglot+";";
		p1.setO(query);
		try {
			client.sendToServer((Object)p1);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		while (input==null);
		CachedRowSetImpl rs=(CachedRowSetImpl)input.getO();
		try {
			while(rs.next())
			{
				count++;
			}
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} 
		return count;
	}
	
	public int getNumOfInAdvance(Date s,Date e,int parkingLot) 
	{
		return getNumOfOrders(s,e,parkingLot);
	}
	/*********************************************************** 
	**********************************************************/
	public static DisabledPlace[] getNumOfDisabled(Date start,Date end,int pl)
	{
		
		int count=0;
		input=null;
		  Packet p=new Packet();
		  p.setE(Kind.get);
		  String query="SELECT * FROM test.Disabled WHERE Disabled.ParkingLotNumber="+pl+" AND Disabled.Start>"+start.getTime()+" AND Disabled.OrderDate<"+end.getTime()+";";
		  p.setO(query);
		  try {
			 
				client.sendToServer((Object)p);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			  while (input==null);
			  CachedRowSetImpl rs=(CachedRowSetImpl)input.getO();
			  
			  try {
				while(rs.next())
				  {
					  count++;
				  }
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			  try {
				rs.beforeFirst();
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			  DisabledPlace[] dp=new DisabledPlace[count];
			  int i=0;
			  try {
				while(rs.next())
				  {
				try {
					
					Date st=new Date(rs.getLong(7)), e=new Date(rs.getLong(8));
					int [] plac={rs.getInt(3),rs.getInt(4),rs.getInt(5)};
					dp[i]=new DisabledPlace(rs.getInt(2),plac,rs.getString(6));
					dp[i].setPid(rs.getInt(1));
					dp[i].setStart(st);
					dp[i].setEnd(e);
				
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
					i++;	
					 // Print out the values
					// System.out.println(rs.getString(1)+"  " +rs.getString(2));
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} 
			  return dp;	
	}
		
	
	
	public int getNumOfFullSubscription()
	{
		int count=0;
		input=null;
		Packet p1=new Packet();
		p1.setE(Kind.get);
		String query="SELECT * FROM test.FullSubscription;";
		p1.setO(query);
		try {
			client.sendToServer((Object)p1);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		while (input==null);
		CachedRowSetImpl rs=(CachedRowSetImpl)input.getO();
		try {
			while(rs.next())
			{
				count++;
			}
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} 
		return count;
	}
	public int getNumOfSubs(int parkinglot) 
	{
		return getNumOfFullSubscription() + getNumOfCasualSubs(parkinglot);
	}
	public int getNumOfCasualSubsWithSeveralCars(int parkinglot)
	{
		int count=0;
		input=null;
		Packet p1=new Packet();
		p1.setE(Kind.get);
		String query="SELECT CasualSubscription.CustomerID FROM test.CasualSubscription WHERE CasualSubscription.ParkingLotNumber="+parkinglot+" GROUP BY CasualSubscription.CustomerID;";
		p1.setO(query);
		try {
			client.sendToServer((Object)p1);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		while (input==null);
		CachedRowSetImpl rs=(CachedRowSetImpl)input.getO();
		try {
			while(rs.next())
			{
				count++;
			}
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} 
		try {
			rs.beforeFirst();
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		String[] s=new String[count];
		int i=0;
		try {
			while(rs.next())
			{
				s[i]=new String(rs.getString(1));
				i++;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		int j=1,num=1; String temp=s[0]; 
		while(j<count)
		{
			if(temp!=s[j])
			{	
				num++;
				temp=s[j];
			}
			j++;
		}
		return num;
	}
	public int getNumOfFullSubsWithSeveralCars()
	{
		int count=0;
		input=null;
		Packet p1=new Packet();
		p1.setE(Kind.get);
		String query="SELECT FullSubscription.CustomerID FROM test.FullSubscription GROUP BY FullSubscription.CustomerID;";
		p1.setO(query);
		try {
			client.sendToServer((Object)p1);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		while (input==null);
		CachedRowSetImpl rs=(CachedRowSetImpl)input.getO();
		try {
			while(rs.next())
			{
				count++;
			}
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} 
		try {
			rs.beforeFirst();
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		String[] s=new String[count];
		int i=0;
		try {
			while(rs.next())
			{
				s[i]=new String(rs.getString(1));
				i++;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		int j=1,num=1; String temp=s[0]; 
		while(j<count)
		{
			if(temp!=s[j])
			{	
				num++;
				temp=s[j];
			}
			j++;
		}
		return num;
	}
	public int getNumOfSubsWithMoreThen1Car(int parkinglot)
	{
		return getNumOfCasualSubsWithSeveralCars(parkinglot)+getNumOfFullSubsWithSeveralCars();
	}

	public void saveComplaintToDB(Complaint complaint) 
	{
		String normal="insert into Complaint values("+complaint.getComplaint_number()+",\""+complaint.getCustomer_id()+"\","+complaint.getDateOfsubmission().getTime()+",\""+complaint.getDescription()+"\","+complaint.isHandled()+",\""+complaint.getWorker_id()+"\",\""+complaint.getResult()+"\","+complaint.getDateOfAnswer().getTime()+","+complaint.getCompensation()+");";
		input=null;
		Packet p1=new Packet();
		p1.setE(Kind.save);
		p1.setO(normal);
		try {
			client.sendToServer((Object)p1);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	} 
	public void savePricesToDB(Prices prices)
	{
		String normal="insert into Prices values("+prices.getDateOfSubmission().getTime()+","+prices.getParkingLotNumber()+","+prices.getOccasionalParkingPlace()+","+prices.getOrderedParkingPlace()+","+prices.getMonthlyRegularSubscriber()+","+prices.getFullMonthlySubscriber()+","+prices.getRegularSubscriberForManyCars()+");";
		input=null;
		Packet p1=new Packet();
		p1.setE(Kind.save);
		p1.setO(normal);
		try {
			client.sendToServer((Object)p1);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	}
	public void saveRequestToDB(Request r)
	{
		String normal="insert into Prices values("+r.getParkingLotNumber()+","+r.getDateOfApproval().getTime()+","+r.isApprovedOrdenied()+","+r.isAskedForChange()+","+r.getChangePrices().getDateOfSubmission().getTime()+","+r.getChangePrices().getOccasionalParkingPlace()+","+r.getChangePrices().getOrderedParkingPlace()+","+r.getChangePrices().getMonthlyRegularSubscriber()+","+r.getChangePrices().getFullMonthlySubscriber()+","+r.getChangePrices().getRegularSubscriberForManyCars()+");";
		input=null;
		Packet p1=new Packet();
		p1.setE(Kind.save);
		p1.setO(normal);
		try {
			client.sendToServer((Object)p1);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	} // moran add this. the parking lot manager will save the request to the DB (parking lot manager will use this)

	public Complaint[] viewCustomerComplaintSQL(String cid)
	{
		int count=0;
		input=null;
		Packet p=new Packet();
		p.setE(Kind.get);
		String query="SELECT * FROM test.Comlaint WHERE Complaint.CustomerID="+cid+";";
		p.setO(query);
		try {
			client.sendToServer((Object)p);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		while (input==null);
		CachedRowSetImpl rs=(CachedRowSetImpl)input.getO();
		try {
			while(rs.next())
			{
				count++;
			}
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} 
		try {
			rs.beforeFirst();
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		Complaint [] c=new Complaint[count];
		int i=0;
		try {
			while(rs.next())
			{
				Date begin=new Date(rs.getLong(3)),ans=new Date(rs.getLong(8));
				
				c[i]=new Complaint(rs.getString(2),rs.getString(4));
				c[i].setComplaint_number(rs.getInt(1));
				c[i].setDateOfsubmission(begin);
				c[i].setHandled(rs.getBoolean(5));
				c[i].setWorker_id(rs.getString(6));
				c[i].setResult(rs.getString(7));
				c[i].setDateOfAnswer(ans);
				c[i].setCompensation(rs.getDouble(9));
				i++;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		return c;
	} // moran add this. this function will make a SQL query so the customer can see his complaints.
	public Complaint[] viewWorkerComplaintSQL(String id)
	{
		int count=0;
		input=null;
		Packet p=new Packet();
		p.setE(Kind.get);
		String query="SELECT * FROM test.Comlaint WHERE Complaint.WorkerID="+id+";";
		p.setO(query);
		try {
			client.sendToServer((Object)p);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		while (input==null);
		CachedRowSetImpl rs=(CachedRowSetImpl)input.getO();
		try {
			while(rs.next())
			{
				count++;
			}
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} 
		try {
			rs.beforeFirst();
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		Complaint [] c=new Complaint[count];
		int i=0;
		try {
			while(rs.next())
			{
				Date begin=new Date(rs.getLong(3)),ans=new Date(rs.getLong(8));
				
				c[i]=new Complaint(rs.getString(2),rs.getString(4));
				c[i].setComplaint_number(rs.getInt(1));
				c[i].setDateOfsubmission(begin);
				c[i].setHandled(rs.getBoolean(5));
				c[i].setWorker_id(rs.getString(6));
				c[i].setResult(rs.getString(7));
				c[i].setDateOfAnswer(ans);
				c[i].setCompensation(rs.getDouble(9));
				i++;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		return c;
	} // moran add this. this function will make a SQL query so the worker can see resulted complaints.
	public Request[] viewRequestsSQL()
	{
		int count=0;
		input=null;
		Packet p=new Packet();
		p.setE(Kind.get);
		String query="SELECT * FROM test.Request;";
		p.setO(query);
		try {
			client.sendToServer((Object)p);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		while (input==null);
		CachedRowSetImpl rs=(CachedRowSetImpl)input.getO();
		try {
			while(rs.next())
			{
				count++;
			}
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} 
		try {
			rs.beforeFirst();
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		Request [] c=new Request[count];
		int i=0;
		try {
			while(rs.next())
			{
				Date begin=new Date(rs.getLong(2)),ans=new Date(rs.getLong(5));
				
				c[i].setParkingLotNumber(rs.getInt(1));
				c[i].setDateOfApproval(begin);
				c[i].setApprovedOrdenied(rs.getBoolean(3));
				c[i].setAskedForChange(rs.getBoolean(4));
				Prices n=new Prices(rs.getInt(1)); n.setOccasionalParkingPlace(rs.getDouble(6)); n.setOrderedParkingPlace(7); n.setParkingLotNumber(8);
				c[i].setChangePrices(n);
				i++;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		return c;
	}
	
	public void deleteRequestSQL(int parkinglotnum,Date date)
	{
		String normal="DELETE FROM test.Request WHERE Request.ParkingLotNumber="+parkinglotnum+" AND Request.SubmissonDate="+date.getTime()+";";
		input=null;
		Packet p1=new Packet();
		p1.setE(Kind.save);
		p1.setO(normal);
		try {
			client.sendToServer((Object)p1);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	} // moran add this. this function will make a SQL query for deleting the request from the DB only if the approveflag is true(because the request table is temporary but dynamic)/
	// generic function for all of us
	public Prices getCurrentPrices(int parkinglotnum)
	{
		int count=0;
		input=null;
		Packet p=new Packet();
		p.setE(Kind.get);
		String query="SELECT * FROM test.Prices WHERE Prices.ParkingLotNumber="+parkinglotnum+";";
		p.setO(query);
		try {
			client.sendToServer((Object)p);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		while (input==null);
		CachedRowSetImpl rs=(CachedRowSetImpl)input.getO();
		try {
			while(rs.next())
			{
				count++;
			}
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} 
		Prices n = null;
		try {
			
			Date d=new Date(rs.getLong(1));
			n = new Prices(rs.getInt(2)); 
			n.setOccasionalParkingPlace(rs.getDouble(3)); 
			n.setOrderedParkingPlace(rs.getDouble(4));
			n.setDateOfSubmission(d);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		return n;
	}
	public Worker[] getWorkers()
	{
		int count=0;
		input=null;
		Packet p=new Packet();
		p.setE(Kind.get);
		String query="SELECT * FROM test.Worker;";

		
		p.setO(query);
		try {
			client.sendToServer((Object)p);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		while (input==null);
		CachedRowSetImpl rs=(CachedRowSetImpl)input.getO();
		try {
			while(rs.next())
			{
				count++;
			}
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} 
		try {
			rs.beforeFirst();
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		Worker [] c=new Worker[count];
		int i=0;
		try {
			while(rs.next())
			{
				c[i]=new Worker(rs.getString(1),rs.getString(2),rs.getString(3),rs.getString(4),rs.getString(7),Role.values()[rs.getInt(6)]);
				c[i].setWorkerNum(rs.getInt(5));
				i++;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		return c;
	}

	public void saveOrderReport(OrderReport r) 
	{
		String normal="insert into OrderReport values("+r.getParkingLot()+","+r.getStart().getTime()+","+r.getEndDate().getTime()+",\""+r.getDescription()+"\","+r.getNumOfOrders()+","+r.getNumOfInAdvance()+","+r.getNumOfSubs()+");";
		input=null;
		Packet p1=new Packet();
		p1.setE(Kind.save);
		p1.setO(normal);
		try {
			client.sendToServer((Object)p1);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	}

	public void saveComplaintReport(ComplaintReport r) 
	{
		String normal="insert into ComlaintReport values("+r.getParkingLot()+","+r.getStart().getTime()+","+r.getEndDate().getTime()+",\""+r.getDescription()+"\");";
		input=null;
		Packet p1=new Packet();
		p1.setE(Kind.save);
		p1.setO(normal);
		try {
			client.sendToServer((Object)p1);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	}

	public void saveDisabledReport(DisabledReport r) 
	{
		String normal="insert into DisabledReport values("+r.getParkingLot()+","+r.getStart().getTime()+","+r.getEndDate().getTime()+",\""+r.getDescription()+"\");";
		input=null;
		Packet p1=new Packet();
		p1.setE(Kind.save);
		p1.setO(normal);
		try {
			client.sendToServer((Object)p1);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	}

	public OneTimeCostumerOrder[] getOneTimeCustomerOrder() 
	{
		int count=0;
		input=null;
		Packet p=new Packet();
		p.setE(Kind.get);
		String query="SELECT * FROM test.OneTimeCustomerOrder;";
		p.setO(query);
		try {
			client.sendToServer((Object)p);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		while (input==null);
		CachedRowSetImpl rs=(CachedRowSetImpl)input.getO();
		try {
			while(rs.next())
			{
				count++;
			}
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} 
		try {
			rs.beforeFirst();
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		OneTimeCostumerOrder [] c=new OneTimeCostumerOrder[count];
		int i=0;
		try {
			while(rs.next())
			{
				Date leave=new Date(rs.getLong(2)),enter=new Date(rs.getLong(3)),actual=new Date(rs.getLong(4));
				
				c[i]=new OneTimeCostumerOrder(rs.getString(1),leave,rs.getString(5),rs.getString(6));
				c[i].setActual_leaving_hour(actual);
				c[i].setEntering_hour(enter);
				c[i].setPayment_status(rs.getBoolean(7));
				i++;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		return c;
	}

	public DisabledPlace getCurrectDisabledParkingSpot(int[] place,int parkingLot) 
	{
		int count=0;
		input=null;
		Packet p=new Packet();
		p.setE(Kind.get);
		String query="SELECT * FROM test.DisabledPlace WHERE DisabledPlace.ParkingLot"+parkingLot+" AND DisabledPlace.Row="+place[0]+" AND DisabledPlace.Col="+place[1]+" AND DisabledPlace.Depth="+place[2]+" AND DisabledPlace.End IS NULL;";
		p.setO(query);
		try {
			client.sendToServer((Object)p);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		while (input==null);
		CachedRowSetImpl rs=(CachedRowSetImpl)input.getO();
		DisabledPlace c = null;
		try {
			rs.next();
			Date start=new Date(rs.getLong(7)), end=new Date(rs.getLong(8));
			int [] plac={rs.getInt(3),rs.getInt(4),rs.getInt(5)};
			c=new DisabledPlace(rs.getInt(2),plac,rs.getString(6));
			c.setPid(rs.getInt(1));
			c.setStart(start);
			c.setEnd(end);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		return c;
	}
  
	public int getParkingLotOfWorker(String id)
	{
		int count=0;
		input=null;
		Packet p=new Packet();
		p.setE(Kind.get);
		String query="SELECT * FROM test.ParkingLotWorker WHERE ParkingLotWorker.WorkerID=\""+id+"\";";
		p.setO(query);
		try {
			client.sendToServer((Object)p);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		while (input==null);
		CachedRowSetImpl rs=(CachedRowSetImpl)input.getO();
		int num=0;
		try {
			rs.next();
			num=rs.getInt(2);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		return num;
	}
	
	public void saveOrder(Order r)
	{
		String normal=null;
		if(r.getActualArrivalDate()==null && r.getActualLeavingDate()==null)
			normal="insert into Order values("+r.getOrderID()+",\""+r.getCustomerID()+"\",\""+r.getCarNumber()+"\","+r.getOrderDate().getTime()+","+r.isCanceled()+","+r.getArrivalDate().getTime()+","+r.getParkingLotNumber()+","+r.getLeavingDate().getTime()+",,,\""+r.getEmail()+"\");";
		else if(r.getActualLeavingDate()==null)
			normal="insert into Order values("+r.getOrderID()+",\""+r.getCustomerID()+"\",\""+r.getCarNumber()+"\","+r.getOrderDate().getTime()+","+r.isCanceled()+","+r.getArrivalDate().getTime()+","+r.getParkingLotNumber()+","+r.getLeavingDate().getTime()+","+r.getActualArrivalDate().getTime()+",,\""+r.getEmail()+"\");";
		else
			normal="insert into Order values("+r.getOrderID()+",\""+r.getCustomerID()+"\",\""+r.getCarNumber()+"\","+r.getOrderDate().getTime()+","+r.isCanceled()+","+r.getArrivalDate().getTime()+","+r.getParkingLotNumber()+","+r.getLeavingDate().getTime()+","+r.getActualArrivalDate().getTime()+","+r.getActualLeavingDate().getTime()+",\""+r.getEmail()+"\");";
		input=null;
		Packet p1=new Packet();
		p1.setE(Kind.save);
		p1.setO(normal);
		try {
			client.sendToServer((Object)p1);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	}

	public void saveOneTimeCustomerOrder(OneTimeCostumerOrder order)
	{
		String normal="insert into OneTimeCustomerOrder values(\""+order.getCostumer_id()+"\","+order.getLeaving_hour().getTime()+","+order.getEntering_hour().getTime()+","+order.getActual_leaving_hour().getTime()+",\""+order.getMail()+"\",\""+order.getCar_number()+"\");";
		input=null;
		Packet p1=new Packet();
		p1.setE(Kind.save);
		p1.setO(normal);
		try {
			client.sendToServer((Object)p1);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	}
	
	public void deleteOneTimeCustomerOrder(OneTimeCostumerOrder order)
	{
		String normal="DELETE FROM test.OneTimeCustomerOrder WHERE OneTimeCustomerOrder.CustomerID=\""+order.getCostumer_id()+"\" AND OneTimeCustomerOrder.EnterHour="+order.getEntering_hour().getTime()+";";
		input=null;
		Packet p1=new Packet();
		p1.setE(Kind.save);
		p1.setO(normal);
		try {
			client.sendToServer((Object)p1);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	}
	
	public void deleteFullSub(FullSubscription order)
	{
		String normal="DELETE FROM test.FullSubscription WHERE FullSubscription.CustomerID=\""+order.getSubscription_number()+"\";";
		input=null;
		Packet p1=new Packet();
		p1.setE(Kind.save);
		p1.setO(normal);
		try {
			client.sendToServer((Object)p1);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	}
	
	public void deleteCasualSub(CasualSubscription order)
	{
		String normal="DELETE FROM test.CasualSubscription WHERE CasualSubscription.CustomerID=\""+order.getSubscription_number()+"\";";
		input=null;
		Packet p1=new Packet();
		p1.setE(Kind.save);
		p1.setO(normal);
		try {
			client.sendToServer((Object)p1);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	}
	
	public void deleteOrder(Order order)
	{
		String normal="DELETE FROM test.Order WHERE Order.OrderID="+order.getOrderID()+";";
		input=null;
		Packet p1=new Packet();
		p1.setE(Kind.save);
		p1.setO(normal);
		try {
			client.sendToServer((Object)p1);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	}
	
	public void saveFullSub(FullSubscription p)
	{
		String normal="insert into FullSubscription values(\""+p.getSubscription_number()+"\",\""+p.getCustomer_id()+"\",\""+p.getCar_number()+"\","+p.getStart_date().getTime()+","+p.getEnd_date().getTime()+","+p.getPenalty()+");";
		input=null;
		Packet p1=new Packet();
		p1.setE(Kind.save);
		p1.setO(normal);
		try {
			client.sendToServer((Object)p1);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	}
	
	public void saveDisabledPlace(DisabledPlace p)
	{
		String normal="insert into DisabledPlace values("+p.getPid()+","+p.getParkingLot()+","+p.getPlace()[0]+","+p.getPlace()[1]+","+p.getPlace()[2]+",\""+p.getDescription()+"\","+p.getStart().getTime()+","+p.getEnd()+");";
		input=null;
		Packet p1=new Packet();
		p1.setE(Kind.save);
		p1.setO(normal);
		try {
			client.sendToServer((Object)p1);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	}
	
	public void deleteCustomer(Customer dp)
	{
		String normal="DELETE FROM test.Customer WHERE Customer.CustomerID=\""+dp.getcustomer_id()+"\";";
		input=null;
		Packet p1=new Packet();
		p1.setE(Kind.save);
		p1.setO(normal);
		try {
			client.sendToServer((Object)p1);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	}
	
	public void saveCustomer(Customer dp)
	{
		String normal="insert into Customer values(\""+dp.getcustomer_id()+"\",\""+dp.getFirst_name()+"\",\""+dp.getLast_name()+"\",\""+dp.getMail()+"\",\""+dp.getPassword()+"\","+dp.getAcc_balance()+");";
		input=null;
		Packet p1=new Packet();
		p1.setE(Kind.save);
		p1.setO(normal);
		try {
			client.sendToServer((Object)p1);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	}
	
	public void deleteDisabledPlace(DisabledPlace dp)
	{
		String normal="DELETE FROM test.DisabledPlace WHERE DisabledPlace.Pid="+dp.getPid()+";";
		input=null;
		Packet p1=new Packet();
		p1.setE(Kind.save);
		p1.setO(normal);
		try {
			client.sendToServer((Object)p1);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	}
	
	public void saveCasualSub(CasualSubscription p)
	{
		String normal="insert into CasualSubscription values(\""+p.getSubscription_number()+"\",\""+p.getCustomer_id()+"\",\""+p.getCar_number()+"\","+p.getStart_date().getTime()+","+p.getEnd_date().getTime()+","+p.getParking_lot_number()+","+p.getleaving_time().getTime()+");";
		input=null;
		Packet p1=new Packet();
		p1.setE(Kind.save);
		p1.setO(normal);
		try {
			client.sendToServer((Object)p1);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	}
	
  /**
   * This method overrides the method in the ChatIF interface.  It
   * displays a message onto the screen.
   *
   * @param message The string to be displayed.
   */
  public void display(String message) 
  {
    System.out.println("> " + message);
  }

  public static void setInput(Packet p)
  {
  	input=p;
  }
  public static Packet getInput()
  {
  	return input;
  }
  //Class methods ***************************************************
  
  /**
   * This method is responsible for the creation of the Client UI.
   *
   * @param args[0] The host to connect to.
   */
  public static void main(String[] args) 
  {
    String host = "";
    int intf=-1;
    int port = 0;  //The port number

    try
    {
    	host =  JOptionPane.showInputDialog ( "enter you IP ctovet" ); 
    	while(intf!=1 && intf!=2)
    		intf =  Integer.valueOf(JOptionPane.showInputDialog ( "enter 1 for Information station or 2 for the network interface" )); 
        
    }
    catch(ArrayIndexOutOfBoundsException e)
    {
      host = "localhost";
    }
    ClientConsole chat= new ClientConsole(host, DEFAULT_PORT);
    DBcontroller db=new DBcontroller(chat);
    Worker[] w=DBcontroller.getWorkers();

    if (intf==1)
    {
    	FrameIS gui=new FrameIS();
		gui.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
	    gui.setSize( 918,405 ); // set frame size
	    gui.setVisible( true ); // display frame
    }
    else if (intf==2)
    {
    	FrameSystem gui=new FrameSystem();
		FrameSystem.getFrame();
		gui.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
	    gui.setSize( 920,410 ); // set frame size
	    gui.setVisible( true ); // display frame
    }
    
    	
    //chat.accept();  //Wait for console data
  }


@Override
public void setMessage(Object m) {
	// TODO Auto-generated method stub
	this.input=(Packet)m;
}
}
//End of ConsoleChat class
